package Q1;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param param string字符串
     * @return string字符串
     */
    public String compressString (String param) {
        // write code here

        StringBuilder stringBuilder = new StringBuilder();

        int len = param.length();
        for (int i = 0; i < len; i++) {
            int p = i;
            int count = 0;
            char ch = param.charAt(p++);
            stringBuilder.append(ch);
            count++;
            while (p < len && param.charAt(p) == ch) {
                count++;
                p++;
            }
            if (count > 1) {
                stringBuilder.append(count);
            }
            i = p - 1;
        }

        return stringBuilder.toString();
    }
}